package com.mspbots.core.ticketai;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.mspbots.core.ticketai.model.TicketReject;
import com.mspbots.core.ticketai.service.TicketRejectService;
import lombok.RequiredArgsConstructor;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.concurrent.Callable;

/**
 * com.mspbots.core.ticketai.TicketRejectController
 *
 * @author Alex bob(https://github.com/vnobo)
 * @date Created by 2019/11/26
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("ticket/reject")
public class TicketRejectController {

    private final TicketRejectService rejectService;

    @GetMapping("user/{username}")
    public Callable list(@PathVariable String username) {
        Assert.notNull(username, "Property or field 'userId' cannot be found on null");
        return () -> this.rejectService.list(Wrappers.<TicketReject>lambdaQuery()
                .eq(TicketReject::getUsername, username).ge(TicketReject::getRejectTime, LocalDateTime.now()));
    }

    @PostMapping("user")
    public Callable save(@RequestBody TicketReject reject) {
        Assert.notNull(reject.getUsername(), "Property or field 'userId' cannot be found on null");
        Assert.notNull(reject.getReason(), "Property or field 'reason' cannot be found on null");
        Assert.notNull(reject.getRejectTime(), "Property or field 'Reject Time' cannot be found on null");
        Assert.notNull(reject.getTicketId(), "Property or field 'Ticket Id' cannot be found on null");
        return () -> this.rejectService.saveRejectTicket(reject);
    }
}
